package com.example.mockapi.controller

import com.example.mockapi.service.ApiDataService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class ApiController {

    @Autowired
    lateinit var apiDataService: ApiDataService

    @GetMapping("/{api}/{entName}/")
    fun getByApi(@PathVariable("api") api: String, @PathVariable("entName") entName: String): Any {
        return apiDataService.getByApi(api, entName)
    }

    @PostMapping("/{api}/{entName}/")
    fun saveApi(@PathVariable("api") api: String, @PathVariable("entName") entName: String, @RequestBody content: Any) {
        apiDataService.save(api, entName, content)
    }

}